package com.framework.main.sys.image;

import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;

import com.opensymphony.xwork2.ActionSupport;
import com.framework.base.util.Struts2Utils;
import com.framework.base.util.SysConfUtil;
/**
 * @Copyright @ 2011 All right reserved
 * @author gyd
 * @description 用于页面图片处理类
 */
public class ImageAction extends ActionSupport {

	public static String rootPath=SysConfUtil.getUpLoadPath();
	private static final long serialVersionUID = 9127325865102689125L;
	private String file;
	public String getFile() {
		return file;
	}
	public void setFile(String file) {
		this.file = file;
	}
	/**
	 * @description 用于处理页面显示图片
	 * @throws Exception
	 */
	public void getImage() throws Exception{
	file=Struts2Utils.getRequest().getParameter("file");	
	FileInputStream hFile = new FileInputStream(new File(rootPath+File.separator+file)); 
	int i = hFile.available(); 
	byte data[] = new byte[i]; 
	hFile.read(data); 
	hFile.close(); 
	Struts2Utils.getResponse().setContentType( "image/*"); // 设置返回的文件类型
	OutputStream toClient = Struts2Utils.getResponse().getOutputStream(); // 得到向客户端输出二进制数据的对象 
	toClient.write(data); // 输出数据 
	toClient.close();
	}
	

}
